package com.diandi.signature.service.impl.contract;

import com.alibaba.fastjson.JSONObject;
import com.diandi.signature.bean.contract.SignatureContract;
import com.diandi.signature.bean.runbatch.SignatureBatchRunInfo;
import com.diandi.signature.contract.FddSignatureContractService;
import com.diandi.signature.enums.fdd.CustomsRoleType;
import com.diandi.signature.enums.fdd.ReturnCode;
import com.diandi.signature.enums.platfrom.BatchRunStatus;
import com.diandi.signature.enums.platfrom.ContractTypeAndTempName;
import com.diandi.signature.enums.platfrom.InterfactType;
import com.diandi.signature.fddtools.FddUtil;
import com.diandi.signature.manager.contract.FddSignatureContractManager;
import com.diandi.signature.manager.contract.SignatureContractManager;
import com.diandi.signature.manager.runbatch.SignatureBatchRunInfoManager;
import com.diandi.signature.mapper.SignatureContractMapper;
import com.diandi.signature.properties.FddProperties;
import com.diandi.signature.properties.SignatureProperties;
import com.diandi.signature.sign.Tools;
import com.diandi.signature.url.CreateTradeNo;
import com.diandi.signature.url.GsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mwz
 * @create 2017-08-31 20:09
 * @version V1.0.0
 * @description description
 */
@Service
public class FddSignatureContractServiceImpl implements FddSignatureContractService {

    private static Logger logger = LoggerFactory.getLogger(FddSignatureContractServiceImpl.class);

    @Autowired
    SignatureProperties signatureProperties;

    @Autowired
    FddSignatureContractManager fddSignatureContractManager;

    @Autowired
    private SignatureContractManager signatureContractManager;

    @Autowired
    private SignatureContractMapper signatureContractMapper;

    @Autowired
    private FddProperties fddProperties;

    @Autowired
    private SignatureBatchRunInfoManager signatureBatchRunInfoManager;

    private static final String ARCHIVED_CODE = "2002";

    private static final String ARCHIVED_MSG = "对不起，该合同已归档！";


    /**
     * 合同模板签章处理
     * @param paramMap
     * @return
     */
    @Override
    public Map<String, String> fddSignatureContractProcess( SignatureContract signatureContract,Map<String,String> querySignatureMap,Map<String,String> paramMap, Map queryGenerateMap) {
        String platTradeNo = paramMap.get("signatureCode");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:开始合同签章："+paramMap.toString()+"--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        try {

            /**
             * 2.1 合同签章
             */
            paramMap.put("notify_url","");
            if ( paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议.getType())){
                returnMap = ProcessTempleteTM01( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议.getType()) ){
                returnMap = ProcessTempleteTM02( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.借款人承诺书.getType()) ){
                returnMap = ProcessTempleteTM03( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.债券转让协议.getType()) ){
                returnMap = ProcessTempleteTM04( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.授权委托协议.getType()) ){
                returnMap = ProcessTempleteTM05( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.委托代扣协议_循环贷.getType()) ) {
                returnMap = ProcessTempleteTM06( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            } else if (paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议_包年服务.getType())){
                returnMap = ProcessTempleteTM07( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            } else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议并委托代扣协议.getType())){
                returnMap = ProcessTempleteTM08( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.委托划款授权书_投资人.getType())){
                returnMap = ProcessTempleteTM09( platTradeNo,signatureContract,querySignatureMap, paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High购房.getType())){
                returnMap = ProcessTempleteTM10( platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议_线上.getType())){
                returnMap = ProcessTempleteTM11(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_有用分期.getType())){
                returnMap = ProcessTempleteTM12(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High酒店.getType())){
                returnMap = ProcessTempleteTM13(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High游艇.getType())){
                returnMap = ProcessTempleteTM14(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_秒借.getType())){
                returnMap = ProcessTempleteTM15(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_苹果专享宝.getType())){
                returnMap = ProcessTempleteTM16(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_车贷宝.getType())){
                returnMap = ProcessTempleteTM17(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_企业机构.getType())){
                returnMap = ProcessTempleteTM18(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.委托代偿协议.getType())){
                returnMap = ProcessTempleteTM21(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.车信宝借款协议.getType())){
                returnMap = ProcessTempleteTM24(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.定期宝借款协议.getType())){
                returnMap = ProcessTempleteTM25(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.活期宝.getType())){
                returnMap = ProcessTempleteTM26(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.代偿协议.getType())){
                returnMap = ProcessTempleteTM28(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }
        } catch (Exception e) {
            SignatureBatchRunInfo batchRunInfo = new SignatureBatchRunInfo();
            batchRunInfo.setSignatureCode(platTradeNo);
            batchRunInfo.setSignatureTrade("");
            if (paramMap.containsKey("userId") && StringUtils.isNotBlank(paramMap.get("userId"))){
                batchRunInfo.setUserId(Long.parseLong(paramMap.get("userId")));
            }
            batchRunInfo.setMerchantNo(paramMap.get("merchantNo"));
            batchRunInfo.setPassCode(paramMap.get("passCode"));
            batchRunInfo.setContractBatchCode(paramMap.get("batchId"));
            batchRunInfo.setContractCode(querySignatureMap.get("contract_id"));
            batchRunInfo.setContractTemplateCode(paramMap.get("contractType"));
            batchRunInfo.setContractTitle(paramMap.get("contractTitle"));
            if (paramMap.containsKey("borrowId") && StringUtils.isNotBlank(paramMap.get("borrowId"))){
                batchRunInfo.setBorrowId(Long.parseLong(paramMap.get("borrowId")));
            }
            batchRunInfo.setInterfaceType(InterfactType.合同签章.getValue());
            batchRunInfo.setPgkMsg(JSONObject.toJSONString(paramMap));
            batchRunInfo.setRetryTimes(3);
            batchRunInfo.setStatus(BatchRunStatus.初始化.getStatus());
            batchRunInfo.setNotifyUrl(paramMap.get("notifyUrl"));

            signatureBatchRunInfoManager.insertSignatureBatchRunInfo(batchRunInfo);

            e.printStackTrace();
            returnMap = Tools.createReturnParams(ReturnCode.err, "", null);
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:合同签章失败："+e.getMessage()+"--");
        }

        if ("1000".equals(returnMap.get("code"))){
            Map<String, String> updateContInfo = new HashMap<String, String>();
            updateContInfo.put("contractDownloadUrl", returnMap.get("download_url"));
            updateContInfo.put("contractViewUrl", returnMap.get("viewpdf_url"));
            updateContInfo.put("contractNo", paramMap.get("contractCode"));
            updateContInfo.put("userId", paramMap.get("userId"));
            signatureContractMapper.updateUrlsByConNo(updateContInfo);
        }

        return returnMap ;
    }


    @Override
    public Map<String, String> fddSignatureContractProcessTimer(SignatureContract signatureContract, Map<String, String> querySignatureMap,
                                                                Map<String, String> paramMap, Map queryGenerateMap, SignatureBatchRunInfo info) {
        String platTradeNo = paramMap.get("platTradeNo");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:开始合同签章："+paramMap.toString()+"--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        try {

            /**
             * 2.1 合同签章
             */
            paramMap.put("notify_url","");
            if ( paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议.getType())){
                returnMap = ProcessTempleteTM01( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议.getType()) ){
                returnMap = ProcessTempleteTM02( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.借款人承诺书.getType()) ){
                returnMap = ProcessTempleteTM03( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.债券转让协议.getType()) ){
                returnMap = ProcessTempleteTM04( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.授权委托协议.getType()) ){
                returnMap = ProcessTempleteTM05( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if ( paramMap.get("contractType").equals(ContractTypeAndTempName.委托代扣协议_循环贷.getType()) ) {
                returnMap = ProcessTempleteTM06( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议_包年服务.getType())){
                returnMap = ProcessTempleteTM07( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议并委托代扣协议.getType())){
                returnMap = ProcessTempleteTM08( platTradeNo,signatureContract,querySignatureMap,  paramMap ,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.委托划款授权书_投资人.getType())){
                returnMap = ProcessTempleteTM09( platTradeNo,signatureContract,querySignatureMap, paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High购房.getType())){
                returnMap = ProcessTempleteTM10( platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.信息咨询与管理服务协议_线上.getType())){
                returnMap = ProcessTempleteTM11(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_有用分期.getType())){
                returnMap = ProcessTempleteTM12(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High酒店.getType())){
                returnMap = ProcessTempleteTM13(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_High游艇.getType())){
                returnMap = ProcessTempleteTM14(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_秒借.getType())){
                returnMap = ProcessTempleteTM15(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_苹果专享宝.getType())){
                returnMap = ProcessTempleteTM16(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_车贷宝.getType())){
                returnMap = ProcessTempleteTM17(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.借款协议_企业机构.getType())){
                returnMap = ProcessTempleteTM18(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.委托代偿协议.getType())){
                returnMap = ProcessTempleteTM21(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.车信宝借款协议.getType())){
                returnMap = ProcessTempleteTM24(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if(paramMap.get("contractType").equals(ContractTypeAndTempName.定期宝借款协议.getType())){
                returnMap = ProcessTempleteTM25(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }else if (paramMap.get("contractType").equals(ContractTypeAndTempName.活期宝.getType())){
                returnMap = ProcessTempleteTM26(platTradeNo,signatureContract,querySignatureMap,paramMap,queryGenerateMap);
            }
        } catch (Exception e) {
            info.setStatus(BatchRunStatus.初始化.getStatus());
            info.setRetryTimes(info.getRetryTimes() - 1);
            signatureBatchRunInfoManager.updateSignatureBatchInfo(info);

            e.printStackTrace();
            returnMap = Tools.createReturnParams(ReturnCode.err, "", null);
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:合同签章失败："+e.getMessage()+"--");
        }
        return returnMap ;
    }



    /**
     * 1.1 借款协议
     */
    public Map<String,String> ProcessTempleteTM01 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议]: 结束处理--");
        return returnMap;
    }

    /**
     *  2.1 信息咨询与管理服务协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM02 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议（包年服务）]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]: 结束处理--");
        return returnMap;

    }

    /**
     * 3.1 借款人承诺书
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM03 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款人承诺书]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));
        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款人承诺书]: 结束处理--");
        return returnMap;
    }


    /**
     * 4.1 债券转让协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM04 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->债券转让协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 1.1 转让人签章
         */
        List <Map<String,String> > assignorList = (List<Map<String, String>>) queryGenerateMap.get("assignorList");
        for(  Map<String,String>  assignorMap : assignorList){
            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = assignorMap.get("customerId").toString();
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= assignorMap.get("customerId").toString();
            String notify_url= querySignatureMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                    doc_title,   sign_keyword,notify_url );
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get( "result").equals("success")) {
                logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;

            }
            paramMap.put("signatureKeyword", sign_keyword);
            paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
            paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));
            fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );
        }

        /**
         * 受让人签章
         */
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("assigneeCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.投资人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("assigneeCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);
        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->债券转让协议]: 结束处理--");
        return returnMap;
    }


    /**
     * 5.1 授权委托协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM05 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->授权委托协议]: 开始处理--");

//        if (querySignatureMap != null){
//            throw new Exception("this is a test exception.");
//        }

        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("licensorCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("licensorCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->授权委托协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = queryGenerateMap.get("licenseeCustomerId").toString();
        client_role =  CustomsRoleType.借款人.getType();
        sign_keyword= queryGenerateMap.get("licenseeCustomerId").toString();
        notify_url= querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->授权委托协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );


        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->授权委托协议]: 结束处理--");
        return returnMap;
    }


    /**
     * 6.1  委托代扣协议_循环贷
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM06 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托代扣协议_循环贷]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 公司签章
         */
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("platCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = "2";
        String client_role =  CustomsRoleType.接入平台.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("platCustomerId").toString();
        String notify_url= paramMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 个人签章
         */
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = queryGenerateMap.get("bCustomerId").toString();
        client_role =  CustomsRoleType.借款人.getType();
        sign_keyword= queryGenerateMap.get("bCustomerId").toString();
        notify_url= querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));
        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同主表信息
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托代扣协议_循环贷]: 结束处理--");
        return returnMap;
    }

    /**
     * 7.1 信息咨询与管理服务协议（包年服务）
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM07 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议（包年服务）]: 开始处理--");

        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
//        String customer_id = queryGenerateMap.get("customerId").toString();
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议（包年服务）]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );



        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议（包年服务）]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->授权委托协议]: 结束处理--");
        return returnMap;
    }

    /**
     * 8.1 借款协议并委托代扣协议
     */
    public Map<String,String> ProcessTempleteTM08 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议并委托代扣协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议并委托代扣协议]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议并委托代扣协议]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议并委托代扣协议]: 借款人{}结束处理--");

        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 公司签章
         */
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = queryGenerateMap.get("platCustomerId").toString();
        batch_id = querySignatureMap.get("batch_id");
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title= querySignatureMap.get("contract_title");
        sign_keyword= queryGenerateMap.get("platCustomerId").toString();
        notify_url= paramMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );


        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议并委托代扣协议]: 结束处理--");
        return returnMap;
    }

    /**
     * 9.1 委托划款授权书_投资人
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     */
    public Map<String,String> ProcessTempleteTM09 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托划款授权书_投资人]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("aCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.投资人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("aCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));
        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托划款授权书_投资人]: 结束处理--");
        return returnMap;
    }

    /**
     * 10.1 借款协议_High购房
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM10 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High购房]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High购房]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High购房]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High购房]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High购房]: 结束处理--");
        return returnMap;
    }

    /**
     * 11.1 信息咨询与管理服务协议_线上
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM11 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议_线上]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议_线上:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议_线上]: 结束处理--");
        return returnMap;

    }


    /**
     * 12.1 借款协议_有用分期
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM12 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_有用分期]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_有用分期]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_有用分期]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_有用分期]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_有用分期]: 结束处理--");
        return returnMap;
    }


    /**
     * 13.1 借款协议_High酒店
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM13 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High酒店]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High酒店]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High酒店]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High酒店]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High酒店]: 结束处理--");
        return returnMap;
    }


    /**
     * 14.1 借款协议_High游艇
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM14 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High游艇]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High游艇]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High游艇]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High游艇]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_High游艇]: 结束处理--");
        return returnMap;
    }
    /**
     * 15.1 借款协议_秒借
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM15 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_秒借]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_秒借]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_秒借]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_秒借]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_秒借]: 结束处理--");
        return returnMap;
    }


    /**
     * 16.1 借款协议_苹果专享宝
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM16 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_苹果专享宝]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_苹果专享宝]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_苹果专享宝]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_苹果专享宝]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_苹果专享宝]: 结束处理--");
        return returnMap;
    }



    /**
     * 17.1 借款协议_车贷宝
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM17 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_车贷宝]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_车贷宝]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_车贷宝]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_车贷宝]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_车贷宝]: 结束处理--");
        return returnMap;
    }

    /**
     * 18.1 借款协议_企业机构
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM18 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_企业机构]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_企业机构]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_企业机构]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_企业机构]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->借款协议_企业机构]: 结束处理--");
        return returnMap;
    }

    /**
     * 21.1 委托代偿协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM21 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->委托代偿协议]: 开始处理--");

//        if (querySignatureMap != null){
//            throw new Exception("this is a test exception.");
//        }

        Map<String, String> returnMap = new HashMap<String, String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("aCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role = CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title = querySignatureMap.get("contract_title");
        String sign_keyword = queryGenerateMap.get("aCustomerId").toString();
        String notify_url = querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto(transaction_id, customer_id, batch_id, client_type, client_role, contract_id,
                doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->委托代偿协议]:完成合同签章result：" + result + "--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))) {
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if (!returnMap.get("result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()) {
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());

        fddSignatureContractManager.insertProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = queryGenerateMap.get("bCustomerId").toString();
        client_role = CustomsRoleType.借款人.getType();
        sign_keyword = queryGenerateMap.get("bCustomerId").toString();
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto(transaction_id, customer_id, batch_id, client_type, client_role, contract_id,
                doc_title, sign_keyword, notify_url);
        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->委托代偿协议]:完成合同签章result：" + result + "--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))) {
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if (!returnMap.get("result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()) {
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }

        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托代偿协议]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->委托代偿协议]: 结束处理--");
        return returnMap;
    }



    /**
     * 24.1 车信宝借款协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM24 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->车信宝借款协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->车信宝借款协议]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->车信宝借款协议]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );

        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->车信宝借款协议]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->车信宝借款协议]: 结束处理--");
        return returnMap;
    }


    /**
     * 25.1 定期宝借款协议
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM25 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->定期宝借款协议]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap , InterfactType.合同签章.getValue() );
        //出借人签章
        List< Map<String,String> > lenderInfoList = (List<Map<String, String>>) queryGenerateMap.get("lenderInfoList");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->定期宝借款协议]: 出借人{}开始处理--");

        for( Map<String,String> resultMap : lenderInfoList ){

            String transaction_id = CreateTradeNo.createTradeNo("QZ");
            String customer_id = resultMap.get("lenderCustomerId");
            String batch_id = querySignatureMap.get("batch_id");
            String client_type = querySignatureMap.get("client_type");
            String client_role =  CustomsRoleType.投资人.getType();
            String contract_id = querySignatureMap.get("contract_id");
            String doc_title= querySignatureMap.get("contract_title");
            String sign_keyword= resultMap.get("lenderCustomerId");
            String notify_url= paramMap.get("notify_url");

            String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                    client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );

            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
            returnMap = GsonUtil.fronJson2Map(result);

            //判断是否已归档，如果已归档通知业务端
            if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
                //返回已归档信息
                returnMap.put("isArchived", "1");
                return returnMap;
            }

            if( !returnMap.get("result").equals("success")){
                logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
                //记录中间状态
                if (returnMap == null || returnMap.isEmpty()){
                    returnMap.put("code", "9999");
                    returnMap.put("msg", "error");
                }
                return returnMap;
            }
            resultMap.put("signatureKeyword",resultMap.get("lenderCustomerId"));
            resultMap.put("signatureTrade",transaction_id);
            fddSignatureContractManager.updateProcessmTM01Data(paramMap, resultMap, returnMap, InterfactType.合同签章.getValue());
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");
        }
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->定期宝借款协议]: 出借人{}结束处理--");

        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessmTM01Data(paramMap, InterfactType.合同签章.getValue());
        //借款人签章
        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("borrowerCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("borrowerCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id,
                client_type,   client_role,   contract_id,  doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")){
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 签章平台处理失败--");
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }
        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );


        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->信息咨询与管理服务协议]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->定期宝借款协议]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->定期宝借款协议]: 结束处理--");
        return returnMap;
    }


    /**
     * 26.1 活期宝
     * @param platTradeNo
     * @param contract
     * @param querySignatureMap
     * @param paramMap
     * @param queryGenerateMap
     * @return
     * @throws Exception
     */
    public Map<String,String> ProcessTempleteTM26 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->活期宝]: 开始处理--");
        Map<String,String> returnMap =  new HashMap<String,String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(  contract, paramMap , InterfactType.合同签章.getValue() );

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("bCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role =  CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title= querySignatureMap.get("contract_title");
        String sign_keyword= queryGenerateMap.get("bCustomerId").toString();
        String notify_url= querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type,   client_role,   contract_id,
                doc_title,   sign_keyword,notify_url );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))){
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if( !returnMap.get( "result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()){
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());


        //平台签章
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = fddProperties.getPlatCustomerId();
        client_type = "2";
        client_role =  CustomsRoleType.接入平台.getType();
        contract_id = querySignatureMap.get("contract_id");
        doc_title = querySignatureMap.get("contract_title");
        sign_keyword = customer_id;
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto( transaction_id,customer_id, batch_id, client_type, client_role, contract_id, doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->活期宝]:完成合同签章result："+result+"--");
        returnMap = GsonUtil.fronJson2Map(result);

        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(  contract, paramMap ,InterfactType.合同签章.getValue());

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        //更新合同归档标志
        signatureContractManager.updateIsArchives(queryGenerateMap.get("contractNo").toString(), "1");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->活期宝]: 结束处理--");
        return returnMap;

    }

    public Map<String,String> ProcessTempleteTM28 ( String platTradeNo,SignatureContract contract,Map<String,String> querySignatureMap, Map<String,String > paramMap , Map queryGenerateMap) throws Exception {
        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->代偿协议]: 开始处理--");

        Map<String, String> returnMap = new HashMap<String, String>();
        /**记录上传合同中间数据到数据库**/
        fddSignatureContractManager.insertProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());

        String transaction_id = CreateTradeNo.createTradeNo("QZ");
        String customer_id = queryGenerateMap.get("aCustomerId").toString();
        String batch_id = querySignatureMap.get("batch_id");
        String client_type = querySignatureMap.get("client_type");
        String client_role = CustomsRoleType.借款人.getType();
        String contract_id = querySignatureMap.get("contract_id");
        String doc_title = querySignatureMap.get("contract_title");
        String sign_keyword = queryGenerateMap.get("aCustomerId").toString();
        String notify_url = querySignatureMap.get("notify_url");

        String result = FddUtil.invokeExtSignAuto(transaction_id, customer_id, batch_id, client_type, client_role, contract_id,
                doc_title, sign_keyword, notify_url);

        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->代偿协议]:完成合同签章result：" + result + "--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))) {
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if (!returnMap.get("result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()) {
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;

        }
        paramMap.put("signatureKeyword", sign_keyword);
        paramMap.put("contractDownloadUrl", returnMap.get("download_url"));
        paramMap.put("contractViewUrl", returnMap.get("viewpdf_url"));

        fddSignatureContractManager.updateProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());

        fddSignatureContractManager.insertProcessInfoData(contract, paramMap, InterfactType.合同签章.getValue());
        transaction_id = CreateTradeNo.createTradeNo("QZ");
        customer_id = queryGenerateMap.get("bCustomerId").toString();
        client_role = CustomsRoleType.借款人.getType();
        sign_keyword = queryGenerateMap.get("bCustomerId").toString();
        notify_url = querySignatureMap.get("notify_url");

        result = FddUtil.invokeExtSignAuto(transaction_id, customer_id, batch_id, client_type, client_role, contract_id,
                doc_title, sign_keyword, notify_url);
        logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章->代偿协议]:完成合同签章result：" + result + "--");
        returnMap = GsonUtil.fronJson2Map(result);

        //判断是否已归档，如果已归档通知业务端
        if (ARCHIVED_CODE.equals(returnMap.get("code")) && ARCHIVED_MSG.equals(returnMap.get("msg"))) {
            //返回已归档信息
            returnMap.put("isArchived", "1");
            return returnMap;
        }

        if (!returnMap.get("result").equals("success")) {
            logger.info("--rcv:platTradeNo:" + platTradeNo + ":[合同生成->合同签章]: 签章平台处理失败--");
            //记录中间状态
            if (returnMap == null || returnMap.isEmpty()) {
                returnMap.put("code", "9999");
                returnMap.put("msg", "error");
            }
            return returnMap;
        }

        paramMap.put("signatureKeyword",sign_keyword );
        paramMap.put("signatureTrade",transaction_id);

        fddSignatureContractManager.updateProcessmTM01Data( paramMap,  paramMap , returnMap,InterfactType.合同签章.getValue() );
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章]: 结束更新数据库状态--");

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->代偿协议]: 借款人{}结束处理--");

        /**
         * 4.1 组织返回信息
         */
        returnMap.put("responseCode", ReturnCode.SUCCESS.getCode());
        returnMap.put("responseMsg", ReturnCode.SUCCESS.getMsg());
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成]: 结束处理--");
        returnMap.put("contractNo", queryGenerateMap.get("contractNo").toString());

        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同生成->合同签章->代偿协议]: 结束处理--");
        return returnMap;
    }
}